<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="time"></div>
    <script>
        // 计算现在到明年09-01的时间差, 然后开始倒计时,
        //并输出在页面上, 输出格式: x天x小时x分钟x秒。
        function times(){
        let time1 = new Date("2022-09-01").getTime();
        let time2 = new Date();
        let timeDif = time1 - time2;
        let day = Math.floor(timeDif/(24*3600*1000));
         //计算天数后剩余的毫秒数
        let leave1 = timeDif%(24*3600*1000);
        let hour = Math.floor(leave1/(3600*1000));
        //计算小时数后剩余的毫秒数
        let leave2 = leave1%(3600*1000);
        let minutes = Math.floor(leave2/(60*1000));
        //计算分钟数后剩余的毫秒数
        let leave3 = leave2%(60*1000);
        let second = Math.floor(leave3/1000);
        // 输出
         document.getElementById('time').innerHTML = day + "天" + hour + "小时" + minutes +  "分钟" + second + "秒";
        
        
    }
        
        setInterval("times();",1000);
        
        
        
       
    </script>
</body>
</html>